using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace LMSData
{
	/// <summary>
	/// Strongly-typed collection for the Assessment class.
	/// </summary>
	[Serializable]
	public partial class AssessmentCollection : ActiveList<Assessment, AssessmentCollection> 
	{	   
		public AssessmentCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the Assessment table.
	/// </summary>
	[Serializable]
	public partial class Assessment : ActiveRecord<Assessment>
	{
		#region .ctors and Default Settings
		
		public Assessment()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public Assessment(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public Assessment(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public Assessment(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("Assessment", TableType.Table, DataService.GetInstance("LMS"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarAssessmentID = new TableSchema.TableColumn(schema);
				colvarAssessmentID.ColumnName = "AssessmentID";
				colvarAssessmentID.DataType = DbType.Int32;
				colvarAssessmentID.MaxLength = 0;
				colvarAssessmentID.AutoIncrement = true;
				colvarAssessmentID.IsNullable = false;
				colvarAssessmentID.IsPrimaryKey = true;
				colvarAssessmentID.IsForeignKey = false;
				colvarAssessmentID.IsReadOnly = false;
				colvarAssessmentID.DefaultSetting = @"";
				colvarAssessmentID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAssessmentID);
				
				TableSchema.TableColumn colvarCourseID = new TableSchema.TableColumn(schema);
				colvarCourseID.ColumnName = "CourseID";
				colvarCourseID.DataType = DbType.Int32;
				colvarCourseID.MaxLength = 0;
				colvarCourseID.AutoIncrement = false;
				colvarCourseID.IsNullable = false;
				colvarCourseID.IsPrimaryKey = false;
				colvarCourseID.IsForeignKey = true;
				colvarCourseID.IsReadOnly = false;
				colvarCourseID.DefaultSetting = @"";
				
					colvarCourseID.ForeignKeyTableName = "Course";
				schema.Columns.Add(colvarCourseID);
				
				TableSchema.TableColumn colvarAssessmentName = new TableSchema.TableColumn(schema);
				colvarAssessmentName.ColumnName = "AssessmentName";
				colvarAssessmentName.DataType = DbType.String;
				colvarAssessmentName.MaxLength = 250;
				colvarAssessmentName.AutoIncrement = false;
				colvarAssessmentName.IsNullable = true;
				colvarAssessmentName.IsPrimaryKey = false;
				colvarAssessmentName.IsForeignKey = false;
				colvarAssessmentName.IsReadOnly = false;
				colvarAssessmentName.DefaultSetting = @"";
				colvarAssessmentName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAssessmentName);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["LMS"].AddSchema("Assessment",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("AssessmentID")]
		public int AssessmentID 
		{
			get { return GetColumnValue<int>("AssessmentID"); }

			set { SetColumnValue("AssessmentID", value); }

		}

		  
		[XmlAttribute("CourseID")]
		public int CourseID 
		{
			get { return GetColumnValue<int>("CourseID"); }

			set { SetColumnValue("CourseID", value); }

		}

		  
		[XmlAttribute("AssessmentName")]
		public string AssessmentName 
		{
			get { return GetColumnValue<string>("AssessmentName"); }

			set { SetColumnValue("AssessmentName", value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
		
		public LMSData.UserAssessmentCollection UserAssessmentRecords()
		{
			return new LMSData.UserAssessmentCollection().Where(UserAssessment.Columns.AssessmentID, AssessmentID).Load();
		}

		public LMSData.AssessmentItemCollection AssessmentItemRecords()
		{
			return new LMSData.AssessmentItemCollection().Where(AssessmentItem.Columns.AssessmentID, AssessmentID).Load();
		}

		#endregion
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Course ActiveRecord object related to this Assessment
		/// 
		/// </summary>
		public LMSData.Course Course
		{
			get { return LMSData.Course.FetchByID(this.CourseID); }

			set { SetColumnValue("CourseID", value.CourseID); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varCourseID,string varAssessmentName)
		{
			Assessment item = new Assessment();
			
			item.CourseID = varCourseID;
			
			item.AssessmentName = varAssessmentName;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varAssessmentID,int varCourseID,string varAssessmentName)
		{
			Assessment item = new Assessment();
			
				item.AssessmentID = varAssessmentID;
				
				item.CourseID = varCourseID;
				
				item.AssessmentName = varAssessmentName;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string AssessmentID = @"AssessmentID";
			 public static string CourseID = @"CourseID";
			 public static string AssessmentName = @"AssessmentName";
						
		}

		#endregion
	}

}

